package com.scau.database.controller.stockbuyer;

import com.scau.database.entity.stockbuyer.*;
import com.scau.database.service.stockbuyer.StockBuyerService;
import freemarker.template.TemplateException;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/order")
public class StockBuyerController {
    @Autowired
    private StockBuyerService stockBuyerService;

    @GetMapping("/getFactory")
    public List<FactoryVO> getFactory(){
        return stockBuyerService.getFactorys();
    }

    @GetMapping("/getWarehouse")
    public List<WarehouseVO> getWarehouse(){
        return stockBuyerService.getWarehouse();
    }

    @GetMapping("/getCommoditySearchResult/{index}")
    public List<SearchCommodityVO> getCommoditySearchResult(@PathVariable("index") String index){
        return stockBuyerService.getSearchCommodities(index);
    }

    @PostMapping("/create")
    public CreateResultDTO createOrder(@RequestBody CreateDTO createDTO){
        return stockBuyerService.createOrder(createDTO);
    }
    @GetMapping("/word/{id}")
    public String  getWordFile(@PathVariable("id") Long id, HttpServletResponse response) throws IOException, TemplateException {
        stockBuyerService.buildWordOrder(response,id);
        return "若未自动下载请尝试刷新该页面";
    }

}
